import java.util.Arrays;

public class demo2 {
    public int minOperations(int[] nums, int x) {
        int n=nums.length;
        int y= Arrays.stream(nums).sum()-x;
        int left=0,right=n-1;
        int ret=-1;
        int sum=0;
        while (left<right){
            sum+=nums[left];
            if(sum==y){
                ret=Math.max(ret,right-left+1);
            }else if(sum<y){
                left++;
            }else{
                right--;
            }
        }
        return ret;
    }
}
